package com.futao.springbootlearn20220224.aware;

import com.futao.springbootlearn20220224.event.UserRegisterEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * 发布事件，也可以使用ApplicationContext发布事件，ApplicationContext也实现了ApplicationEventPublisherAware
 *
 * @author futao@gmail.com
 * @date 2022/3/9
 */
@Slf4j
@Component
public class ApplicationEventPublisherAwareDemo implements ApplicationEventPublisherAware {
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        log.info("Aware发布事件");
        applicationEventPublisher.publishEvent(new UserRegisterEvent(this, new UserRegisterEvent.NewUser(123L, "从aware发出的event")));
    }
}
